package com.gok.einvoice.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.gok.einvoice.common.core.page.TableDataInfo;
import com.gok.einvoice.common.utils.StringUtils;
import com.gok.einvoice.web.dto.EmployeePageDTO;
import com.gok.einvoice.web.entity.Employee;
import com.gok.einvoice.web.mapper.EmployeeMapper;
import com.gok.einvoice.web.service.IEmployeeService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * 员工Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-24
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    /**
     * 员工列表分页查询
     * @param pageDTO
     * @return
     */
    @Override
    public TableDataInfo pageQuery(EmployeePageDTO pageDTO) {
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper<Employee>()
                .like(StringUtils.hasText(pageDTO.getName()), Employee::getName, pageDTO.getName());
        //获取该条件下的总数
        long total = this.count(wrapper);

        //开始分页
        PageHelper.startPage(pageDTO.getPage(), pageDTO.getPageSize());
        List<Employee> list = this.list(wrapper);
        if (CollectionUtils.isEmpty(list)) {
            return new TableDataInfo(Collections.emptyList(), 0);
        }

        //获取该条件下的总数
        return new TableDataInfo(list, (int) total);
    }
}
